statephip = zeros(1,4);
stateuphip = zeros(1,4);
tkchoicestate = zeros(1,4);
stateum = zeros(1,4);
tkchoicestate1 = zeros(1,4);
tkchoicestateu = zeros(1,4);
nn = 15;
tau1 = 96;
tau2 = 128;
A = generA(nn,tau1,tau2);
h = 1/(nn+1);
%t = h^2;
%t = 5;
%t = 4;
%t = 3;
%t = 2;
t = 1;
%p = 0;
v = rand(nn^3,1);
[T,Y]=ode15s(@(t,y)A*y,[0,t],v);
rows = 1:length(Y);
%Y0 = expv(t,A,v,eps);
[Y0,tkchoicestate1,uphipm1max] = uphipm1(t,A,v,eps);
[Yphi,statephip] = phip(t,A,v,eps);
[Yuphi,stateuphip] = uphip(t,A,v,eps);
[Yum,stateum] = umphipm(t,A,v,eps); 
[Y1,tkchoicestate,phipmmax] = phipmactual(t,A,v,eps);
[Yu1,tkchoicestateu,uphipmmax] = uphipm(t,A,v,eps); 
phipmmax
uphipm1max
uphipmmax
subplot(3,2,1)
plot(rows,Yphi-Y(end,:)','-r')
title('phip')
subplot(3,2,2)
plot(rows,Yuphi-Y(end,:)','-r')
title('uphip')
subplot(3,2,3)
plot(rows,Y1-Y(end,:)','-r')
title('phipm')
subplot(3,2,4)
plot(rows,Yum-Y(end,:)','-r')
title('umphipm')
subplot(3,2,5)
rows = 1:length(Y0);
plot(rows,Y0-Y(end,:)','-r')
title('uphipm1')
subplot(3,2,6)
plot(rows,Yu1-Y(end,:)','-r')
title('uphipm')

stateall = [statephip;stateuphip;tkchoicestate;stateum;tkchoicestate1;tkchoicestateu]
%%
%p =1;
v = 10*rand(nn^3,2);
[T,Y]=ode15s(@(t,y)A*y+v(:,2),[0,t],v(:,1));
[Y0,tkchoicestate1,uphipm1max] = uphipm1(t,A,v,eps);
[Yphi,statephip] = phip(t,A,v,eps);
[Yuphi,stateuphip] = uphip(t,A,v,eps);
[Yum,stateum] = umphipm(t,A,v,eps); 
[Y1,tkchoicestate,phipmmax] = phipmactual(t,A,v,eps);
[Yu1,tkchoicestateu,uphipmmax] = uphipm(t,A,v,eps); 
phipmmax
uphipm1max
uphipmmax
subplot(3,2,1)
plot(rows,Yphi-Y(end,:)','-r')
title('phip')
subplot(3,2,2)
plot(rows,Yuphi-Y(end,:)','-r')
title('uphip')
subplot(3,2,3)
plot(rows,Y1-Y(end,:)','-r')
title('phipm')
subplot(3,2,4)
plot(rows,Yum-Y(end,:)','-r')
title('umphipm')
subplot(3,2,5)
rows = 1:length(Y0);
plot(rows,Y0-Y(end,:)','-r')
title('uphipm1')
subplot(3,2,6)
plot(rows,Yu1-Y(end,:)','-r')
title('uphipm')

stateall = [statephip;stateuphip;tkchoicestate;stateum;tkchoicestate1;tkchoicestateu]